<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Explicit decorator declaration</title>
<link rel="stylesheet" href="../../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../index.html" title="Boost.Test">
<link rel="up" href="../decorators.html" title="Decorators">
<link rel="prev" href="suite_level_decorators.html" title="Suite-level decorators">
<link rel="next" href="../fixtures.html" title="Fixtures">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="suite_level_decorators.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../decorators.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../fixtures.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="boost_test.tests_organization.decorators.explicit_decorator_declaration"></a><a class="link" href="explicit_decorator_declaration.html" title="Explicit decorator declaration">Explicit
        decorator declaration</a>
</h4></div></div></div>
<p>
          There is another way of associating a decorator set with test units. Macro
          <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_decorator.html" title="BOOST_TEST_DECORATOR"><code class="computeroutput"><span class="identifier">BOOST_TEST_DECORATOR</span></code></a> indicates
          that its set of decorators is to be applied to the test unit or <span class="emphasis"><em>test
          case sequence</em></span> that immediately follows the declaration.
        </p>
<h6>
<a name="boost_test.tests_organization.decorators.explicit_decorator_declaration.h0"></a>
          <span class="phrase"><a name="boost_test.tests_organization.decorators.explicit_decorator_declaration.example_descr"></a></span><a class="link" href="explicit_decorator_declaration.html#boost_test.tests_organization.decorators.explicit_decorator_declaration.example_descr">Example:
          explicit decorator declaration</a>
        </h6>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
                  <p>
                    Code
                  </p>
                </th></tr></thead>
<tbody><tr><td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_MODULE</span> <span class="identifier">decorator_00</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">included</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">data</span><span class="special">/</span><span class="identifier">test_case</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>

<span class="keyword">namespace</span> <span class="identifier">utf</span>  <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">unit_test</span><span class="special">;</span>
<span class="keyword">namespace</span> <span class="identifier">data</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">unit_test</span><span class="special">::</span><span class="identifier">data</span><span class="special">;</span>

<span class="identifier">BOOST_TEST_DECORATOR</span><span class="special">(*</span> <span class="identifier">utf</span><span class="special">::</span><span class="identifier">description</span><span class="special">(</span><span class="string">"with description"</span><span class="special">))</span>
<span class="identifier">BOOST_DATA_TEST_CASE</span><span class="special">(</span><span class="identifier">test_1</span><span class="special">,</span> <span class="identifier">data</span><span class="special">::</span><span class="identifier">xrange</span><span class="special">(</span><span class="number">4</span><span class="special">))</span>
<span class="special">{</span>
    <span class="identifier">BOOST_TEST</span><span class="special">(</span><span class="identifier">sample</span> <span class="special">&gt;=</span> <span class="number">0</span><span class="special">);</span>
<span class="special">}</span>
</pre>
                </td></tr></tbody>
</table></div>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th>
                  <p>
                    Output
                  </p>
                </th></tr></thead>
<tbody><tr><td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">&gt;</span> <span class="identifier">decorator_00</span> <span class="special">--</span><span class="identifier">list_content</span>
<span class="identifier">test_1</span><span class="special">*:</span> <span class="identifier">with</span> <span class="identifier">description</span>
<span class="identifier">test_1</span><span class="special">*:</span> <span class="identifier">with</span> <span class="identifier">description</span>
<span class="identifier">test_1</span><span class="special">*:</span> <span class="identifier">with</span> <span class="identifier">description</span>
<span class="identifier">test_1</span><span class="special">*:</span> <span class="identifier">with</span> <span class="identifier">description</span>
</pre>
                </td></tr></tbody>
</table></div>
<p>
          In the above example a decorator is applied to a <a class="link" href="../test_cases/test_case_generation.html" title="Data-driven test cases">data-driven
          test case</a>. Macro <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_dataset.html" title="BOOST_DATA_TEST_CASE"><code class="computeroutput"><span class="identifier">BOOST_DATA_TEST_CASE</span></code></a> cannot take
          the decorator set as one of its arguments, therefore the explicit decorator
          declaration is used. Macro <a class="link" href="../../utf_reference/test_org_reference/test_org_boost_test_dataset.html" title="BOOST_DATA_TEST_CASE"><code class="computeroutput"><span class="identifier">BOOST_DATA_TEST_CASE</span></code></a> generates
          a sequence of 4 test cases. The decorator set is applied to each of them.
        </p>
<p>
          Another use case for the explicit decorator declaration is when you intend
          for your test program to compile also on compilers without variadic macros.
          In this case it is recommended that you use the more verbose syntax. It
          is summarized in the following table:
        </p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                  <p>
                    Test unit to register
                  </p>
                </th>
<th>
                  <p>
                    Concise syntax
                  </p>
                </th>
<th>
                  <p>
                    Universal syntax
                  </p>
                </th>
</tr></thead>
<tbody>
<tr>
<td>
                  <p>
                    test case
                  </p>
                </td>
<td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test_case</span><span class="special">,</span> <span class="special">*</span><span class="identifier">decor1</span><span class="special">()</span> <span class="special">*</span><span class="identifier">decor2</span><span class="special">())</span>
<span class="special">{</span>
  <span class="comment">// assertions</span>
<span class="special">}</span>
</pre>
                </td>
<td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_TEST_DECORATOR</span><span class="special">(*</span><span class="identifier">decor1</span><span class="special">()</span> <span class="special">*</span><span class="identifier">decor2</span><span class="special">())</span>
<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test_case</span><span class="special">)</span>
<span class="special">{</span>
  <span class="comment">// assertions</span>
<span class="special">}</span>
</pre>
                </td>
</tr>
<tr>
<td>
                  <p>
                    test case with fixture
                  </p>
                </td>
<td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_FIXTURE_TEST_CASE</span><span class="special">(</span><span class="identifier">test_case</span><span class="special">,</span> <span class="identifier">Fx</span><span class="special">,</span> <span class="special">*</span><span class="identifier">decor1</span><span class="special">()</span> <span class="special">*</span><span class="identifier">decor2</span><span class="special">())</span>
<span class="special">{</span>
  <span class="comment">// assertions</span>
<span class="special">}</span>
</pre>
                </td>
<td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_TEST_DECORATOR</span><span class="special">(*</span><span class="identifier">decor1</span><span class="special">()</span> <span class="special">*</span><span class="identifier">decor2</span><span class="special">())</span>
<span class="identifier">BOOST_FIXTURE_TEST_CASE</span><span class="special">(</span><span class="identifier">test_case</span><span class="special">,</span> <span class="identifier">Fx</span><span class="special">)</span>
<span class="special">{</span>
  <span class="comment">// assertions</span>
<span class="special">}</span>
</pre>
                </td>
</tr>
<tr>
<td>
                  <p>
                    test suite
                  </p>
                </td>
<td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_AUTO_TEST_SUITE</span><span class="special">(</span><span class="identifier">test_suite</span><span class="special">,</span> <span class="special">*</span><span class="identifier">decor1</span><span class="special">()</span> <span class="special">*</span><span class="identifier">decor2</span><span class="special">())</span>

  <span class="comment">// test units</span>

<span class="identifier">BOOST_AUTO_TEST_SUITE_END</span><span class="special">()</span>
</pre>
                </td>
<td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_TEST_DECORATOR</span><span class="special">(*</span><span class="identifier">decor1</span><span class="special">()</span> <span class="special">*</span><span class="identifier">decor2</span><span class="special">())</span>
<span class="identifier">BOOST_AUTO_TEST_SUITE</span><span class="special">(</span><span class="identifier">test_suite</span><span class="special">)</span>

  <span class="comment">// test units</span>

<span class="identifier">BOOST_AUTO_TEST_SUITE_END</span><span class="special">()</span>
</pre>
                </td>
</tr>
<tr>
<td>
                  <p>
                    test suite with fixture
                  </p>
                </td>
<td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_FIXTURE_TEST_SUITE</span><span class="special">(</span><span class="identifier">test_suite</span><span class="special">,</span> <span class="identifier">Fx</span><span class="special">,</span> <span class="special">*</span><span class="identifier">decor1</span><span class="special">()</span> <span class="special">*</span><span class="identifier">decor2</span><span class="special">())</span>

  <span class="comment">// test units</span>

<span class="identifier">BOOST_AUTO_TEST_SUITE_END</span><span class="special">()</span>
</pre>
                </td>
<td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_TEST_DECORATOR</span><span class="special">(*</span><span class="identifier">decor1</span><span class="special">()</span> <span class="special">*</span><span class="identifier">decor2</span><span class="special">())</span>
<span class="identifier">BOOST_FIXTURE_TEST_SUITE</span><span class="special">(</span><span class="identifier">test_suite</span><span class="special">,</span> <span class="identifier">Fx</span><span class="special">)</span>

  <span class="comment">// test units</span>

<span class="identifier">BOOST_AUTO_TEST_SUITE_END</span><span class="special">()</span>
</pre>
                </td>
</tr>
<tr>
<td>
                  <p>
                    data-driven test case
                  </p>
                </td>
<td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="comment">// not doable</span>
</pre>
                </td>
<td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_TEST_DECORATOR</span><span class="special">(*</span><span class="identifier">decor1</span><span class="special">()</span> <span class="special">*</span><span class="identifier">decor2</span><span class="special">())</span>
<span class="identifier">BOOST_DATA_TEST_CASE</span><span class="special">(</span><span class="identifier">test_case</span><span class="special">,</span> <span class="identifier">data</span><span class="special">,</span> <span class="identifier">var</span><span class="special">)</span>
<span class="special">{</span>
  <span class="comment">// assertions</span>
<span class="special">}</span>
</pre>
                </td>
</tr>
<tr>
<td>
                  <p>
                    test case template
                  </p>
                </td>
<td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="comment">// not doable</span>
</pre>
                </td>
<td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_TEST_DECORATOR</span><span class="special">(*</span><span class="identifier">decor1</span><span class="special">()</span> <span class="special">*</span><span class="identifier">decor2</span><span class="special">())</span>
<span class="identifier">BOOST_AUTO_TEST_CASE_TEMPLATE</span><span class="special">(</span><span class="identifier">test_case</span><span class="special">,</span> <span class="identifier">T</span><span class="special">,</span> <span class="identifier">type_list</span><span class="special">)</span>
<span class="special">{</span>
  <span class="comment">// assertions</span>
<span class="special">}</span>
</pre>
                </td>
</tr>
<tr>
<td>
                  <p>
                    test case template with fixture
                  </p>
                </td>
<td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="comment">// not doable</span>
</pre>
                </td>
<td>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">BOOST_TEST_DECORATOR</span><span class="special">(*</span><span class="identifier">decor1</span><span class="special">()</span> <span class="special">*</span><span class="identifier">decor2</span><span class="special">())</span>
<span class="identifier">BOOST_FIXTURE_TEST_CASE_TEMPLATE</span><span class="special">(</span><span class="identifier">test_case</span><span class="special">,</span> <span class="identifier">T</span><span class="special">,</span> <span class="identifier">type_list</span><span class="special">,</span> <span class="identifier">Fx</span><span class="special">)</span>
<span class="special">{</span>
  <span class="comment">// assertions</span>
<span class="special">}</span>
</pre>
                </td>
</tr>
</tbody>
</table></div>
<p>
          Throughout the reminder of this documentation we use only the concise syntax.
        </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001-2020 Boost.Test contributors<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="suite_level_decorators.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../decorators.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../fixtures.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
